
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>狼人杀助手 - 真假预言家版</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            padding: 20px;
            background-color: #f8f8f8;
        }
        h1 {
            text-align: center;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        table, th, td {
            border: 1px solid #ccc;
        }
        th, td {
            text-align: center;
            padding: 10px;
        }
        .input-section {
            margin-bottom: 20px;
        }
        .input-section input {
            margin-right: 10px;
            padding: 5px;
        }
        .input-section button {
            padding: 5px 10px;
            background-color: #007bff;
            color: white;
            border: none;
            cursor: pointer;
        }
        .input-section button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
    <h1>狼人杀助手 - 真假预言家版</h1>
    <table id="probabilityTable">
        <thead>
            <tr>
                <th>玩家</th>
                <th>身份</th>
                <th>狼人概率</th>
                <th>村民概率</th>
                <th>存活状态</th>
            </tr>
        </thead>
        <tbody>
            <!-- 动态生成 -->
        </tbody>
    </table>

    <div>
        <h2>预言家操作</h2>
        <select id="seerPlayer">
            <option value="玩家5">真预言家</option>
            <option value="玩家1">假预言家1</option>
            <option value="玩家2">假预言家2</option>
        </select>
        <input type="text" id="seerTarget" placeholder="目标玩家">
        <select id="seerAction">
            <option value="查杀">查杀</option>
            <option value="金水">金水</option>
        </select>
        <button onclick="performSeerAction()">执行</button>
    </div>

    <script>
        // 初始化玩家数据
        const players = Array.from({ length: 12 }, (_, i) => ({
            name: `玩家${i + 1}`,
            role: i < 4 ? "狼人" : (i === 4 ? "预言家" : (i === 5 ? "女巫" : (i === 6 ? "猎人" : (i === 7 ? "守卫" : "村民")))),
            wolfProbability: i < 4 ? 1 : 0,
            villagerProbability: i >= 4 ? 1 : 0,
            isAlive: true,
            isRealSeer: i === 4, // 玩家5是真预言家
            credibility: i === 4 ? 1 : 0 // 真预言家初始可信度为1，假预言家为0
        }));

        // 渲染表格
        function renderTable() {
            const tableBody = document.querySelector("#probabilityTable tbody");
            tableBody.innerHTML = "";
            players.forEach((player) => {
                const row = document.createElement("tr");
                row.innerHTML = `
                    <td>${player.name}</td>
                    <td>${player.role}</td>
                    <td>${(player.wolfProbability * 100).toFixed(2)}%</td>
                    <td>${(player.villagerProbability * 100).toFixed(2)}%</td>
                    <td>${player.isAlive ? "存活" : "死亡"}</td>
                `;
                tableBody.appendChild(row);
            });
        }

        // 动态调整概率
        function adjustProbabilities() {
            const alivePlayers = players.filter(player => player.isAlive);
            const totalWolfProbability = alivePlayers.reduce((sum, p) => sum + p.wolfProbability, 0);
            const totalVillagerProbability = alivePlayers.reduce((sum, p) => sum + p.villagerProbability, 0);

            alivePlayers.forEach(player => {
                player.wolfProbability /= totalWolfProbability;
                player.villagerProbability /= totalVillagerProbability;
            });
        }

        // 执行预言家操作
        function performSeerAction() {
            const seerPlayerName = document.getElementById("seerPlayer").value;
            const targetPlayerName = document.getElementById("seerTarget").value;
            const actionType = document.getElementById("seerAction").value;

            const seerPlayer = players.find(p => p.name === seerPlayerName);
            const targetPlayer = players.find(p => p.name === targetPlayerName);

            if (seerPlayer && targetPlayer) {
                if (actionType === "查杀") {
                    if (seerPlayer.isRealSeer) {
                        targetPlayer.wolfProbability = 1;
                        targetPlayer.villagerProbability = 0;
                    } else {
                        targetPlayer.wolfProbability *= 0.5;
                        targetPlayer.villagerProbability *= 1.5;
                    }
                } else if (actionType === "金水") {
                    if (seerPlayer.isRealSeer) {
                        targetPlayer.wolfProbability = 0;
                        targetPlayer.villagerProbability = 1;
                    } else {
                        targetPlayer.wolfProbability *= 1.5;
                        targetPlayer.villagerProbability *= 0.5;
                    }
                }

                // 调整全局概率
                adjustProbabilities();
                renderTable();
            }
        }

        // 初始化
        renderTable();
    </script>
</body>
</html>
